# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
from itemadapter import ItemAdapter
from pymongo import MongoClient

client = MongoClient()
collection_shunyi = client["lianjia_ershoufang"]["shunyi"]
collection_haidian = client["lianjia_ershoufang"]["haidian"]


class LianjiaPipeline:
    def process_item(self, item, spider):
        if spider.name == "shunyi":

            print(item)
            print('*'*100)
            collection_shunyi.insert(dict(item))
        if spider.name == "haidian":

            print(item)
            print('-'*100)
            collection_haidian.insert(dict(item))
        return item
